package com.morizhang.merchanmanager.api.service;

import com.alibaba.fastjson.JSONObject;
import com.morizhang.merchanmanager.api.ApiResult;
import com.morizhang.merchanmanager.api.IService;
import com.morizhang.merchanmanager.api.dao.AlertDao;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.Method;

@ServiceAnnotation(name = "AlertService")
public class AlertService implements IService {
    @Autowired
    AlertDao alertDao;

    @Override
    public ApiResult callService(JSONObject requestParams) throws Exception {
        String callMethodName = requestParams.getString("requestMethod");
        Method callMethod = this.getClass().getMethod(callMethodName, JSONObject.class);
        ApiResult result = (ApiResult)callMethod.invoke(this, requestParams);
        result.setSuccess(true);
        return result;
    }

    public ApiResult selectAllAlert(JSONObject requestParams) {
        ApiResult result = new ApiResult();
        result.setData(alertDao.selectAllAlert());
        return result;
    }

    public ApiResult deleteAlert(JSONObject requestParams) {
        String serialNo = requestParams.getJSONObject("data").getString("serialNo");
        alertDao.deleteAlert(serialNo);
        return new ApiResult();
    }
}
